"""
个人中心页面测试
"""
import time
from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.common.by import By
from selenium.webdriver.support import wait
from selenium.webdriver.support.wait import WebDriverWait

from Utils.Utils import ForumDriver


class PersonalCenter:
    url = ""
    driver = ""

    def __init__(self):
        self.driver = ForumDriver.driver
        self.url = "http://127.0.0.1:58080/index.html"
        self.driver.get(self.url)

    # 修改信息
    def ModifyInfo(self):
        # 添加显示等待
        time.sleep(2)
        # 点击主页图标
        self.driver.find_element(By.CSS_SELECTOR, " #index_nav_avatar").click()
        # 点击个人中心按钮
        self.driver.find_element(By.CSS_SELECTOR, "#index_user_settings").click()

        # 修改昵称测试
        ele = self.driver.find_element(By.CSS_SELECTOR, "#setting_input_nickname")
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_nickname").click()
        time.sleep(2)
        ele.clear()
        wait_se = WebDriverWait(self.driver, 5)
        if wait_se.until(EC.presence_of_all_elements_located(
                (By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div > h2"))):
            ele.send_keys("befor")
        else:
            ele.send_keys("after")
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_nickname").click()
        print("修改昵称测试成功")

        # 修改邮箱测试
        time.sleep(3)
        element_01 = self.driver.find_element(By.CSS_SELECTOR, "#setting_input_email")
        self.driver.execute_script("arguments[0].scrollIntoView();", element_01)
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_email").click()
        time.sleep(2)
        element_01.clear()
        if self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div > h2"):
            element_01.send_keys("123456")
        else:
            element_01.send_keys("654321")
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_email").click()
        print("修改邮箱测试成功")

        # 修改电话号码测试
        time.sleep(2)
        element_02 = self.driver.find_element(By.CSS_SELECTOR, "#setting_input_phoneNum")
        self.driver.execute_script("arguments[0].scrollIntoView();", element_02)
        time.sleep(4)
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_phoneNum").click()
        element_02.clear()
        if self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div"):
            element_02.send_keys("123456")
        else:
            element_02.send_keys("654321")
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_phoneNum").click()
        print("修改电话号码测试成功")

        # 个人简介测试
        element_03 = self.driver.find_element(By.CSS_SELECTOR, "#settings_textarea_remark")
        self.driver.execute_script("arguments[0].scrollIntoView();", element_03)
        time.sleep(4)
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_remark").click()
        element_03.clear()
        time.sleep(2)
        if self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div"):
            element_03.send_keys("before")
        else:
            element_03.send_keys("after")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_remark").click()
        print("修改简介测试成功")
        # 修改头像测试
